M365 Onboarding with Location-based Routing

The M365 Location-based Routing script is shown below. Variables highlighted in orange should be changed according to customer deployment.

Copy
# Begin of Microsoft onboarding script


        # Addition for Location based routing


        # Script variables
            [String]$OnlinePstnGateway="{{SBC.OnlinePstnGateway}}"
            [String]$CustomerId="{{SBC.SbcSiteName}}"


        # PSTN Gateway Variables
        [Int]$SipSignalingPort=5061
        [Int]$MaxConcurrentSessions=100


        # Add Network region if not exists
            if(Get-CsTenantNetworkRegion | Where-Object {$_.Identity -eq "India"})
                {
                    continue
                }else {
                    New-CsTenantNetworkRegion -NetworkRegionID "India";
                }


        # Add Network Site if not exists
            if(Get-CsTenantNetworkSite | Where-Object {$_.Identity -like "{{SBC.SbcSiteName}}"})
                {
                    continue
                }else {
                    New-CsTenantNetworkSite -NetworkSiteID "{{SBC.SbcSiteName}}" -NetworkRegionID "India" -EnableLocationBasedRouting $true -Description "Default Site created by AudioCodes LiveCloud";
                }


        # Add example subnet to the network site
            if(Get-CsTenantNetworkSubnet | Where-Object {$_.Identity -like "169.254.0.0"})
                {
                    continue
                }else {
                    New-CsTenantNetworkSubnet -SubnetID "169.254.0.0"  -MaskBits "16" -NetworkSiteID "{{SBC.SbcSiteName}}" -Description "Example subnet set by AudioCodes LiveCloud";
                }


        # Add example trusted IP address
            if(Get-CsTenantTrustedIPAddress | Where-Object {$_.Identity -like "169.254.0.1"})
                {
                    continue
                }else {
                    New-CsTenantTrustedIPAddress -IPAddress 169.254.0.1 -MaskBits 32 -Description "Example Trusted IP Address set by AudioCodes LiveCloud";
                }


        # Add OnlinePSTNGateway
            if(Get-CsOnlinePSTNGateway | Where-Object {$_.Identity -like "{{SBC.OnlinePstnGateway}}"})
                {
                    continue
                }else {
    
                # The line below might require customization based on the customer needs, like a change in the SipSignalingPort or attributes needs to be added like MaxConcurrentSessions
                      New-CsOnlinePstnGateway -Fqdn "{{SBC.OnlinePstnGateway}}" -Enabled $true -SipSignalingPort $SipSignalingPort -ForwardCallHistory $True -ForwardPai $True -MediaBypass $True -MaxConcurrentSessions $MaxConcurrentSessions -GatewaySiteLbrEnabled $true –GatewaySiteID "{{SBC.SbcSiteName}}" ;
                }


        # Create CallingPolicy named UMPPreventTollBypass
            if(Get-CsTeamsCallingPolicy | Where-Object {$_.Identity -like "Tag:UMPPreventTollBypass"})
                {
                    continue
                }else {
                    New-CsTeamsCallingPolicy -Identity "UMPPreventTollBypass" -AllowCallForwardingToPhone $True -Description "Allow Teams calling, preventing toll bypass" -PreventTollBypass $True;
                }
  

        # End addition for Location based routing


        # From original onboarding script


        # Add PSTN Usage record Unrestricted if not exists
            if(Get-CsOnlinePstnUsage | Where-Object Usage -NotContains "Unrestricted"
                {
                    Set-CsOnlinePstnUsage -Identity Global -Usage @{Add="Unrestricted"};
                }


        # Add Online Voice Route Unrestricted if not exists, else add additional PSTN Gateway to the OnlinePstnGatewayList if there is a new PSTN Gateway
            if(Get-CsOnlineVoiceRoute | Where-Object {$_.Identity -eq "Unrestricted"})
                {
                    Write-host "The CsOnlineVoiceRoute named Unrestricted already exists."
                    if(Get-CsOnlineVoiceRoute -Identity "Unrestricted" | Where-Object {$_.OnlinePstnGatewayList -NotContains "{{SBC.OnlinePstnGateway}}"})
                    {
                        Write-host "A new PSTN Gateway is added to the the OnlinePstnGatewayList."
                        Set-CsOnlineVoiceRoute -Identity "Unrestricted" -OnlinePstnGatewayList  @{add="{{SBC.OnlinePstnGateway}}"}
                    }
                }else {
                    Write-host "The CsOnlineVoiceRoute named Unrestricted does not exist, creating one."
                    New-CsOnlineVoiceRoute -Identity "Unrestricted" -NumberPattern ".*" -OnlinePstnGatewayList @{add="{{SBC.OnlinePstnGateway}}"} -Priority 1 -OnlinePstnUsages @{add="Unrestricted"};
                }


        # Add Voice Routing Policy Unrestricted if not exists
            if(Get-CsOnlineVoiceRoutingPolicy | Where-Object {$_.Identity -like "Tag:Unrestricted"})
                {
                    continue
                }else {
                    New-CsOnlineVoiceRoutingPolicy -Identity "Unrestricted" -OnlinePstnUsages "Unrestricted";
                }


        # End of M365 onboarding script
        ;